<template>
<div class="login">
    <div class="logo"><img src="../../static/img/logo.png" class="logoimg"/></div>
    <div class="form">
        <h1 class="title">杜尚美环保拖鞋代理商系统</h1>
        <div class="group_name">
            <span class="name_label" >账号</span>
            <input type="text" class="name_input" v-model="userName" placeholder="请输入手机号"/>
        </div>
        <div class="group_name">
            <span class="name_label" >密码</span>
            <input type="password" class="name_input" v-model="password" placeholder="请输入密码"/>
        </div>
        <div class="loginbtn" v-on:click="loginAction">登录</div>

    </div>
    </div>
</template>

<script>
import info from '../info.js'
import { TopTips } from 'we-vue'
export default {
  name: "login",
  data(){
    return{
      userName:"",
      password:""
    }
  },
  components: {
  
  },
 
  methods:{
   loginAction: function(){
     var name = this.userName;
     var pass = this.password;
     var contentjson = {"userName":name,"password":this.$md5(pass)};
     let reqArguments = {
       openid:info.appid,
       content:JSON.stringify(contentjson),
       method:'dusun.crm.api.user.login',
       version:info.version,
     }
     const sign = this.$md5(JSON.stringify(reqArguments).replace(/\\/g,''))
     const _this = this;
     $.ajax({
        url:"http://192.168.124.6:8866/gateway", 
        type:"post",
        data:{
          openid:info.appid,
          content:JSON.stringify(contentjson),
          method:'dusun.crm.api.user.login',
          sign:sign,
          version:info.version,
        },
        success:function(data) {
          if(data.code == "200"){
            var token = data.data.token;
            $.cookie("token", token); 
            $.cookie("userId",data.data.userId);
            $.cookie("type",data.data.type);//2:代理商 3:BD
            _this.$router.push({
                path: '/index',
                query:{
                    type: data.data.type
                }
            })
            _this.$router.push({path:'/index',query:{type:data.data.type}})
            // if(data.data.type == 2 ){
            //     _this.$router.push({path:'/index',query:{type:data.data.type}})
            // }else if(data.data.type == 3){
            //     _this.$router.push({path:'/bdindex',query:{type:data.data.type}})
            // }
          }else if(data.code == "3001") {
            TopTips({
              message: '用户名密码错误',
              duration: 5000
            })
          }else if(data.code == "3002"){
            TopTips({
              message: '账户已冻结',
              duration: 5000
            })
          }else if(data.code == "3003") {
            TopTips({
              message: '账号不存在',
              duration: 5000
            })
          }else if(data.code == "2001") {
            TopTips({
              message: '用户名或密码不能为空',
              duration: 5000
            })
          }
          
        },
        error:function(error){
          console.log("error")
        }
      })
    }
  },
};
</script>


<style lang="scss">
@import '../base/reset.scss';
@import "../base/common.scss";


.login{
    margin-top: 60px;
    @include text-overflow;
    padding:0 pxTorem(60);
    .logo {
      width:pxTorem(160);
      height:pxTorem(160);
      margin:0 auto;
      //border:1px solid #e5e5e5;
      //border-radius:pxTorem(20);
      overflow:hidden;
      .logoimg {
        width:100%;
      }
    }
    .title {
      color:#505050;
      font-size:pxTorem(34);
      text-align:center;
      font-weight:bold;
      margin:pxTorem(60) 0;
    }
    .group_name {
      margin-top:pxTorem(40);
      border-bottom: 1px solid #eeeeee;
      text-align:left;
      height:pxTorem(80);
      line-height:pxTorem(80);
      .name_label {
        font-size:pxTorem(32);
        display: inline-block;
        width:20%;
        color: #505050;
      }
      .name_input {
        font-size:pxTorem(32);
        height:pxTorem(80);
        display: inline-block;
        width:80%;
        color: #505050;
        
      }
    }
    .loginbtn {
      height:pxTorem(80);
      color:white;
      background:#6DA93F;
      line-height:pxTorem(80);
      border-radius:pxTorem(10);
      margin: pxTorem(80) auto;
    }
  }

</style>